package com.sihan.swvp.quartz;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.sihan.swvp.common.CommonUtil;
import com.sihan.swvp.service.sys.LogService;
import com.sihan.swvp.sync.Synchronizer;

/**
 * 任务同步工具
 * @author jch
 *
 */
@Component
public class JobSync extends SyncQuartz{
	
	public Synchronizer synchronizer;
	@Autowired
	public LogService logService;
	
	@Override
	public void execute() {
		// TODO Auto-generated method stub
		System.err.println("execute job:" + synchronizer.jobid);
		Date date = new Date();
		try {
			getSynchronizer().sync();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			logService.addSystemLog("执行定时任务", "定时任务", 0, 
					CommonUtil.date2string(date),"执行工作<",synchronizer.jobid,">时发生错误："+e.getMessage());
		}
	}
	public Synchronizer getSynchronizer() {
		
		return synchronizer;
	}
	public void setSynchronizer(Synchronizer synchronizer) {
		
		this.synchronizer = synchronizer;
	}
	
}
